define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            $('.isQiYong').click(function() {
                $("#type").val($(this).attr("t"));
                $("#status").val($(this).attr("value"));
                $("#tform").submit();
            });
            return false;
        },
        sponsororderedit: function () {
            $("#iExpand").change(function() {
                if ($("#iExpand").prop("checked")) {
                    $(".vShow").show('fast');
                } else {
                    $(".vShow").hide("slow");
                }
            });
            $(".v-title").click(function (){
                //$(this).parents(".vShowHgroup").hide("slow");
                $(this).parents(".vShowHgroup").remove();
            });
            //新增
            var tNum=0;
            $(".addVroom").click(function (){
                if (tNum >3) return ;
                $('.v-room-content').append($('#innerHtml').html());
                tNum++;
                return false;
            });
            $(".btn-success").click(function (){
                $(".alert").alert('设置成功！');
                return true;
            });



        },
        list: function (){
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'sponsor/sponsororder/list',
                    add_url: '',
                    edit_url: '',
                    del_url: 'sponsor/sponsororder/del',
                    multi_url: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'orderId', title: '订单ID'},
                        {field: 'planName', title: __('标题')},
                        {field: 'totalMoney', title: __('总价')},
                        {field: 'status', title: __('状态')},
                        {field: 'buyTime', title: __('下单时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'id', title: __('详情')},
                        {field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: 'detail',
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'sponsor/sponsororder/orderdetail',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                onLoadSuccess: function (data) {
                    // 在表格第次加载成功后,刷新左侧菜单栏彩色小角标,支持一次渲染多个
                    // 如果需要在进入后台即显示左侧的彩色小角标,请使用服务端渲染方式,详情修改application/admin/controller/Index.php
                    Backend.api.sidebar({
                        'sponsor/sponsororder/list': data.total
                    });
                    Toastr.info("左侧角标已经刷新成功");
                }
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        edit: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});